package LeetCode;

public class LC_101_SymmetricTree {
    public static void main(String[] args) {

    }

    class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int x) {
            val = x;
        }
    }

    static class Solution {
        public boolean isSymmetric(TreeNode root) {
            return root == null || isSame(root.left, root.right);
        }

        private boolean isSame(TreeNode left, TreeNode right) {
            if (left == null && right == null)
                return true;
            if ((left != null && right == null) || (left == null && right != null)) {
                return false;
            } else {
                return left.val == right.val && isSame(left.left, right.right) && isSame(left.right, right.left);
            }
        }
    }
}
